//
//  UIBarButtonItem+extansion.swift
//  NewWeiBo
//
//  Created by 吴天益 on 2017/7/22.
//  Copyright © 2017年 ttt. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    //便利构造函数
    convenience init(title: String,target: Any?,action: Selector,imageName: String? = nil){
        
        let button = UIButton()
        
        button.addTarget(target, action: action, for: .touchUpInside)
        
        button.setTitle(title, for: .normal)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        
        //设置图片
        if(imageName != nil){
            if let imageN = imageName {
                
                button.setImage(UIImage(named: imageN)?.withRenderingMode(.alwaysOriginal), for: .normal)
                button.setImage(UIImage(named: imageN + "_highlighted")?.withRenderingMode(.alwaysOriginal), for: .highlighted)
            }else{
                print("图片名称为空")
            }
        }
        
        button.sizeToFit()
        
        //调用其他构造函数实现实例化
        self.init(customView: button)
        
}
    
    
    
    
    
    

}
